#include "windowxp.h"

WindowXP::WindowXP(QWidget *parent) : QMainWindow(parent)
{
    initWindow();
}

void WindowXP::initWindow()
{
    //获取菜单栏
    m_Bar = menuBar();

    //菜单栏添加菜单
    file_menu = m_Bar->addMenu("文件");
    edit_menu = m_Bar->addMenu("编辑");

    //文件菜单添加菜单项
    QAction * openAct = file_menu->addAction(QIcon(":/img/account.png"),"打开");
    // 打开菜单项设置快捷键
    openAct->setShortcut(QKeySequence("ctrl+n"));
    // Qt5
    connect(openAct,&QAction::triggered,this,&WindowXP::openNewWindow);
    //文件菜单添加菜单项
    QAction * undoAct = edit_menu->addAction(QIcon(":/img/account.png"),"撤销");
    //添加分割线
    file_menu->addSeparator();
    file_menu->addAction(QIcon(":/img/account.png"),"测试");
    // 打开菜单项设置快捷键
    undoAct->setShortcut(QKeySequence("ctrl+p"));

    edit = new QTextEdit;
    //    connect(undoAct,&QAction::triggered,edit,&QTextEdit::undo);
    connect(undoAct,&QAction::triggered,this,&WindowXP::customUndo);
    setCentralWidget(edit);

    QMenu* menu2 = edit_menu->addMenu("二级菜单");
    QMenu* menu3 = menu2->addMenu("三级菜单");
    menu3->addAction("编辑测试");
//    edit->setFont(1);

    s_Bar = statusBar();
    //默认在左侧
//    s_Bar->showMessage("这是一个状态栏");
//    s_Bar->showMessage("left");
    //左侧组件
    s_Bar->addWidget(new QLabel("left"));
    s_Bar->addWidget(new QLabel("left1"));
    //右侧组件
    s_Bar->addPermanentWidget(new QLabel("right"));
    s_Bar->addPermanentWidget(new QLabel("right1"));
//    s_Bar->setVisible(false);

    //添加工具栏
    t_Bar1 = addToolBar("toolbar1");
    t_Bar1->addAction(openAct);
    t_Bar1->addAction(undoAct);
    //设置图标和文本同时显示
    t_Bar1->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    addToolBar("toolbar2");
    addToolBar("toolbar3");

    //浮动面板 锚接部件 DockWidget
    QDockWidget * d_window = new QDockWidget("函数窗口");
    d_window->setWidget(new FunWindow);
//    QPushButton *btn =new QPushButton("btn");
//    btn->setParent(d_window);
    addDockWidget(Qt::LeftDockWidgetArea,d_window);

    QDockWidget * d_window1 = new QDockWidget("窗口");
    d_window1->setWidget(new FunWindow);
//    QPushButton *btn =new QPushButton("btn");
//    btn->setParent(d_window);
    addDockWidget(Qt::LeftDockWidgetArea,d_window1);
}

void WindowXP::openNewWindow()
{
    QWidget * w = new QWidget;
    w->setWindowTitle("newWindow");
    w->show();
}

void WindowXP::customUndo()
{
    edit->undo();
}
